import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/17 9:47
 * @description 二叉搜索树中序遍历 存储在list中，然后get, 或者不用list
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int kthSmallest(TreeNode root, int k) {
        List<Integer> list = new ArrayList<>();
        dfs(root, list);
        return list.get(k - 1);
    }
    public void dfs(TreeNode root, List<Integer> list) {
        if(root == null) {
            return;
        }
        dfs(root.left, list);
        list.add(root.val);
        dfs(root.right, list);
    }
}
